package com.yonyou.brigade.rtpnr.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.rtpnr.model.EntInfo;
import com.yonyou.brigade.rtpnr.service.IEntInfoService;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/6/13.
 */
@Service
public class EntInfoServiceImpl implements IEntInfoService {

    @Autowired
    @Qualifier("briChannelServiceImpl")
    private IBriChannelService briChannelService;

    public EntInfo getEntInfoByOrg(String orgpk)
    {
        EntInfo entInfo=null;
        BriChannel briChannel = briChannelService.getEnableChannelByOrgAndChannel(orgpk,"rtpnr");
        if(briChannel!=null)
        {
            JSONObject jsonObject= JSON.parseObject(briChannel.getConfig());
            entInfo = (EntInfo)JSON.parseObject(jsonObject.toJSONString(), EntInfo.class);
        }
        return  entInfo;
    }

    public EntInfo getEntInfoByTenantOrg(String tenant,String orgpk)
    {
        EntInfo entInfo=null;
        BriChannel briChannel = briChannelService.getEnableInfoByTenantOrg(tenant,orgpk,"rtpnr");
        if(briChannel!=null)
        {
            JSONObject jsonObject= JSON.parseObject(briChannel.getConfig());
            entInfo = (EntInfo)JSON.parseObject(jsonObject.toJSONString(), EntInfo.class);
        }
        return  entInfo;
    }


}
